﻿using System.Data.SqlClient;

namespace Coleotrack.Models.Setup
{
    public class DatabaseViewModel
    {
        public string Host { get; set; }
        public bool IntegratedAuth { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public string Database { get; set; }

        public string ConnectionString
        {
            get
            {
                var sqlConnectionStringBuilder = new SqlConnectionStringBuilder();
                sqlConnectionStringBuilder.DataSource = this.Host;
                if (this.IntegratedAuth)
                {
                    sqlConnectionStringBuilder.IntegratedSecurity = false;
                    sqlConnectionStringBuilder.UserID = this.Username;
                    sqlConnectionStringBuilder.Password = this.Password;
                }
                else
                {
                    sqlConnectionStringBuilder.IntegratedSecurity = true;
                }

                sqlConnectionStringBuilder.InitialCatalog = this.Database;

                return sqlConnectionStringBuilder.ToString();
            }
        }
    }
}